;
; utilities to work with types
;
;
;





;
; converts given symbol type to its string equivalent
;
(defun stringify-symbol-type (context sym-type)
  (assert (symbolp sym-type))
  (let ((type-info (get-type-info sym-type)))
    (printm context (type-info-lang-name type-info))
    ))

(defun stringify-list-type (context complex-type)
  (assert (= (length complex-type) 2))
  (let ((type-modifier (first complex-type)))
    (cond
     ((eq type-modifier 'ptr)
      (progn
	(stringify-typename context (second complex-type))
	(printm context " *")
	))
     ((eq type-modifier 'const)
      (progn
	(printm context "const ")
	(stringify-typename context (second complex-type))))
     (t (error (format nil "unknown type modifier: ~a" type-modifier)))
     )))

(defun stringify-typename (context typename)
  (if (symbolp typename)
      (stringify-symbol-type context typename)
      (stringify-list-type context typename)
      ))

(defun stringify-symbol-name (context sym-name)
  (assert (symbolp sym-name))
  (printm context
	  (format nil "~(~a~)" sym-name) ; make lowercase
	  )
  )

;
; stringifies arguments list
;
(defun stringify-arg-list (context args)
  (printm context "(")
  (let ((is-first t))
    (dolist (arg args)

      ; "type - name" pair expected
      (assert (= (length arg) 2))


      ; delimeter between brace (previous printed arg) and
      ; argument to be printed
      (printm context (if is-first
			  (progn
			    (setf is-first nil)
			    " ")
			  ", "))

      (stringify-typename context (first arg))
      (printm context " ")
      (stringify-symbol-name context (second arg))
      )
    (printm context (if is-first ")" " )"))))
